/**   
 * @Title: SportteryFootballHemaiLannchCommunicater.java 
 * @Package com.esun.rabbit2.communicaters.sportteryfootball 
 * @Description: (竞彩足球发起合买接口) 
 * @author: City Jiangsy@500wan.com   
 * @date: 2011-8-22 上午11:44:01  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters.sportteryfootball;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.DistributionChannels;
import com.esun.config.Key;
import com.esun.config.Language;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: SportteryFootballHemaiLannchCommunicater
 * @Description: (竞彩足球发起合买接口)
 * @author: City Jiangsy@500wan.com
 * @date: 2011-8-22 上午11:44:01
 * 
 */
public class SportteryFootballHemaiLannchCommunicater extends ServerCommunicater {

	private String msgServer; // 服务器信息
	private boolean isSucceed = false;

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String msgServer) {
		this.msgServer = msgServer;
	}

	public boolean isBuySucceed(int zhushu, int beishu, long allMoney, int guoguanType, long allNum, Long buyNum, long baodiNum, int tichengNum, String codes, String sgtype, boolean isBaodi)
			throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_SPORTTERFOOTBALL_HEMAILAUNCHER));
		list.add(mapItem(BussinessCode.PASER_CK, UserInfo.getUserInfo().getUserSession()));
		list.add(mapItem(Key.KEY_CHANNEL, DistributionChannels.QUDAO));
		list.add(mapItem(Key.KEY_LOTID, Config.JINGCAIZUQIU));
		list.add(mapItem(Key.KEY_PLAYID, Config.JINGCAIZUQIU_RQSPF));
		list.add(mapItem(Key.KEY_ALLMONEY, Long.toString(allMoney)));
		list.add(mapItem(Key.KEY_SGTYPE, sgtype));
		list.add(mapItem(Key.KEY_BEISHU, Integer.toString(beishu)));
		list.add(mapItem(Key.KEY_CODES, codes));
		list.add(mapItem(Key.KEY_TITLE, Language.STR_HEMAI_TITLE));
		list.add(mapItem(Key.KEY_ANUMBER, Long.toString(allNum)));
		list.add(mapItem(Key.KEY_BUYNUMBER, Long.toString(buyNum)));
		// 必填3 自由过关 2 多串过关
		if (guoguanType == 3) {
			list.add(mapItem(Key.KEY_GGGROUP, Config.STR_ZIYOU_GUOGUAN));
		} else if (guoguanType == 2) {
			list.add(mapItem(Key.KEY_GGGROUP, Config.STR_DUOCHUAN_GUOGUAN));
		} else {

		}
		EDebug.o(SportteryFootballHemaiLannchCommunicater.this, " step 11 ");
		list.add(mapItem(Key.KEY_ZHUSHU, Integer.toString(zhushu)));
		// list.add(mapItem(SETBUYUSER, ""));
		// list.add(mapItem(CONTENT, ""));
		if (isBaodi) {
			list.add(mapItem(Key.KEY_ISBAODI, Config.NUM1));
			list.add(mapItem(Key.KEY_BAODINUMBER, Long.toString(baodiNum)));
		} else {
			list.add(mapItem(Key.KEY_ISBAODI, Config.NUM0));
		}
		list.add(mapItem(Key.KEY_RATIO, Integer.toString(tichengNum)));

		// 写入服务器返回信息
		super.getServerResponse(list, true);
		setMsgServer(super.getErrorMSG());
		if (super.getState() == 100) {
			isSucceed = true;
			UserInfo.getUserInfo().setUserBalance(super.getResult().get(Key.KEY_USERMONEY));

		} else {
			isSucceed = false;
		}
		return isSucceed;

	}

	/**
	 * @Title: mapItem
	 * @Description: (工具类,用于构建AraayList单条内容)
	 * @param @param name 参数名
	 * @param @param value 参数值
	 * @param @return map-+
	 * 
	 * @return HashMap<String,String> 返回类型
	 * @throws
	 */
	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
